<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
html, body {
    height: 100%;
}

body {
    background-repeat: no-repeat;
}

.bg1 {
    background-image: url("./3.jpg");
}

.bg2 {
    background-image: url("./4.jpg");
}

.bg3 {
    background-image: url("./9.jpeg");
}

.bg4 {
    background-image: url("./a.jpg");
}
</style>
</head>
<body>
<script>
var cs = ["bg1", "bg2", "bg3", "bg4"];
/*var index = 0;
document.body.onclick = function (){
    document.body.className = cs[index % cs.length];
    index++;

}*/
document.body.onclick = function (){
    document.body.className = cs[randomInt(0, cs.length - 1)];
}

/**
 作者:李振超      2017年7月31日 11:36
 返回随机的 [from, to] 之间的整数(包括from，也包括to)
 */
function randomInt(from, to){
    return parseInt(Math.random() * (to - from + 1) + from);
}

</script>
</body>
</html>